using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Farm.AStar
{
    public class Node : IComparable<Node>
    {
        //网格坐标
        public Vector2Int gridPosition;
        //距离起始点的距离
        public int gCost = 0;
        //距离终点的距离
        public int hCost = 0;
        //权重
        public int FCost => gCost + hCost;
        //当前格子是否是障碍物
        public bool isObstacle = false;
        //上一个节点
        public Node parentNode;

        public Node(Vector2Int pos)
        {
            gridPosition = pos;
            parentNode = null;
        }

        public int CompareTo(Node other)
        {
            //比较Fcost的值，小于括号中的返回值小于0，等于则返回值为0，大于则返回值大于0
            int result = FCost.CompareTo(other.FCost);
            if (result==0)
            {
                result = hCost.CompareTo(other.hCost);
            }

            return result;
        }
    }
}

